package tst

import java.nio.ByteBuffer
import java.nio.channels.*

FileOutputStream fileOutputStream = new FileOutputStream("c:/temp/testfile.txt");
FileChannel channel = fileOutputStream.getChannel();
FileLock lock = channel.lock()
println "valid:${lock.isValid()},\t shared:${lock.isShared()}"


ByteBuffer sendBuffer=ByteBuffer.wrap((new Date().toString()+" 写入\n").getBytes());

channel.write(sendBuffer);
println 'write completed'
lock.close();
channel.close();
fileOutputStream.close()
